package com.ellricky.teacher.ui.mycourse

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import com.andr.common.ui.fragment.BaseToolBarFragment
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.adapter.course.JobTrainingActivity
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.ui.ErCodeActivity
import com.ellricky.baselib.ui.RecentlyCourseActivity
import com.ellricky.baselib.ui.cla.ClassManageActivity
import com.ellricky.baselib.ui.cla.ClassManageFragment
import com.ellricky.baselib.ui.course.FileLearnListActivity
import com.ellricky.baselib.ui.course.TYPE_LEARN
import com.ellricky.baselib.ui.course.TYPE_REMARK
import com.ellricky.baselib.ui.order.RenewalManageActivity
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.jump
import com.ellricky.teacher.R
import com.ellricky.teacher.jumpStuMsgList
import com.ellricky.teacher.ui.mycourse.course.ChangeSchoolActivity
import com.ellricky.teacher.ui.mycourse.student.MyStudentActivity
import kotlinx.android.synthetic.main.tc_fragment_my_course.*

class MyCourseFragment : BaseToolBarFragment<Void, BasePresenter<Void>>() {

    private lateinit var classManageFragment: ClassManageFragment

    companion object {
        fun newInstance(): MyCourseFragment {
            val fragment = MyCourseFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getContentLayout(): Int = R.layout.tc_fragment_my_course

    override fun initUIView(root: View) {
        super.initUIView(root)
        mTvTitle.setText(R.string.tc_my_course)
        setRightBtn(R.drawable.tc_icon_ercode)

        tvClassRoomManager.setOnClickListener(this)
        tvStuManage.setOnClickListener(this)
        tvConsume.setOnClickListener(this)
        tvEvaluate.setOnClickListener(this)

        tvJobTraining.setOnClickListener(this)
        tvRenewal.setOnClickListener(this)
        tvRecentlyCourse.setOnClickListener(this)
        tvChangeSchool.setOnClickListener(this)

        flDayTask.setOnClickListener(this)
        flFileLearn.setOnClickListener(this)

        classManageFragment = ClassManageFragment.newInstance(true)
        childFragmentManager.beginTransaction()
            .replace(R.id.frgContainer, classManageFragment)
            .commit()
    }

    override fun onClickView(view: View) {
        super.onClickView(view)

        when (view) {
            mIbBack -> {
                jumpStuMsgList(this)
            }
            mBtnRight -> {
                EAppUtil.jumpPageWithNoParam(this, ErCodeActivity::class.java)
            }
            tvClassRoomManager -> {
                EAppUtil.jumpClassManage(this)
            }
            tvStuManage -> {
                EAppUtil.jumpPageWithNoParam(this, MyStudentActivity::class.java)
            }
            tvConsume -> {
                val bundle = Bundle().apply {
                    putBoolean(BaseConstant.KEY_SHOW_BACK, true)
                }
                EAppUtil.jumpCommonFragment(
                    requireContext(),
                    BaseConstant.FRAGMENT_CLASS_CONSUME,
                    bundle
                )
            }
            tvEvaluate -> {
                EAppUtil.jumpPageWithParam(mConext, ClassManageActivity::class.java,
                    Bundle().apply {
                        putString(BaseConstant.KEY_TYPE, BaseConstant.TYPE_EVALUATE)
                    })
            }
            tvJobTraining -> {
                EAppUtil.jumpPageWithNoParam(this, JobTrainingActivity::class.java)
            }
            tvRenewal -> {
                jump<RenewalManageActivity>()
            }
            tvRecentlyCourse -> {
                EAppUtil.jumpPageWithNoParam(
                    mContext,
                    RecentlyCourseActivity::class.java
                )
            }
            tvChangeSchool -> {
                EAppUtil.jumpPageWithNoParam(this, ChangeSchoolActivity::class.java)
            }
            flDayTask -> {
                EAppUtil.jumpPageWithId(
                    this,
                    FileLearnListActivity::class.java,
                    TYPE_REMARK
                )
            }
            flFileLearn -> {
                EAppUtil.jumpPageWithId(
                    this,
                    FileLearnListActivity::class.java,
                    TYPE_LEARN
                )
            }
        }
    }

    override fun onResume() {
        super.onResume()
        val load = LocalCacheUtil.isReloadData()
        if (load) {
            loadDataOnInit()
            classManageFragment.loadClassRooms()
        }
        LocalCacheUtil.setIsReloadData(true)
    }

    @SuppressLint("SetTextI18n")
    private fun loadDataOnInit() {
    }
}
